package com.moss.cloud.auth.biz.controller;

import com.moss.cloud.auth.biz.exception.AuthErrorType;
import com.moss.cloud.auth.biz.service.IAuthService;
import com.moss.cloud.common.core.constant.ServiceList;
import com.moss.cloud.common.core.model.Result;
import com.moss.cloud.common.core.utils.BooleanHandel;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;


@Slf4j
@RestController
@RequestMapping(ServiceList.AUTH)
public class AuthController {
    private IAuthService authService;
    public AuthController(IAuthService authService){
        this.authService = authService;
    }

    @PostMapping("/logout")
    public Result<?> logout(HttpServletRequest request) {
        return Result.success(authService.logout(request));
    }

    @GetMapping("/smsCode")
    public Result<?> getSmsCode(@RequestParam("mobile") String mobile) {
        BooleanHandel.trueThrow(StringUtils.isBlank(mobile)).throwMessage(AuthErrorType.MOBILE_EMPTY);
        return Result.success(authService.getSmsCode(mobile));
    }
}
